package com.kolon.business.mngr.login.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.kolon.business.mngr.login.dao.LoginDao;
import com.kolon.framework.constant.Constant;
import com.kolon.framework.interfaces.SimpleController;
import com.kolon.framework.util.ComUtil;
import com.kolon.framework.util.MsgUtil;

@Controller("com.kolon.business.mngr.login.controller.LoginController")
public class LoginController implements SimpleController {

	@Resource(name="com.kolon.business.mngr.login.dao.LoginDaoImpl")
	private LoginDao loginDao;
	
	@SuppressWarnings({ "unchecked", "rawtypes" })
	@RequestMapping(value="/business/mngr/login/login.do")
	public ModelAndView controller(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		// 도메인
		String url = MsgUtil.getMessage("mngr.login.url");
		// 아이디, 암호 파라미터
		String mngrId = ComUtil.getNullCheck(request.getParameter("mngrId"));
		String mngrPw = ComUtil.getNullCheck(request.getParameter("mngrPw"));
		Map map = new HashMap();
		map.put("mngrId", mngrId);
		map.put("mngrPw", mngrPw);
		// 회원 정보 조회
		Map mngrMap = loginDao.getMap(map);
		// 리턴
		ModelAndView modelAndView = new ModelAndView();
		if (mngrMap == null || mngrMap.isEmpty())
		modelAndView.setViewName("redirect:/business/mngr/index.do");
		else {
		request.getSession().setAttribute(Constant.SESSION_MNGR_INFO, mngrMap);
		modelAndView.setViewName("redirect:"+url);
		}
		return modelAndView;
	}

}
